<template>
	<div>

		<basic-container>
			<avue-crud :option="option4" :data="data" :page.sync="page" @size-change="sizeChange" @row-update="editChange"
			@row-del="delChange"
			 @row-save="addChange" @current-change="currentChange" @search-change="searchChange">
			</avue-crud>
		</basic-container>
		<el-dialog title="删除提示" :visible.sync="box" v-dialogdrag :class="{'avue-dialog':type==0}" width="40%">
		  <span>删除设备信息会导致设备离线,确认删除?</span>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="box=false">取 消</el-button>
		    <el-button type="primary" @click="delSubmit">确 定</el-button>
		  </span>
		</el-dialog>
	</div>
	
	
</template>

<script>
	import {
		mapGetters
	} from "vuex";
	import request from '@/router/axios';
	import {
		baseUrl
	} from '@/config/env';

	export default {
		name: "wel",
		data() {
			return {
				data: [],
				 type:'',
				 box:false,
				page: {
					currentPage: 1,
					total: 0,
					layout: "total,pager,prev, next",
					background: false,
					pageSize: 10
				},
				delval:null,
			};
		},
		computed: {
			...mapGetters(["userInfo"]),
			option4() {
				this.getList({
					'page': 1,
					'pageSize': this.page.pageSize
				})
				
				
				return {
					//index: true,
					align: 'center',
					menuAlign: 'center',
					column: [{
							label: this.$t("wel.table.id"),
							prop: "id",
							search: true,
							searchClearable: false,
							searchPlaceholder: 'ID搜索',
							searchSize: "mini",
							//editDisabled:true,
							addDisplay: false,
							editDisplay: false,
						},
						{
							label: this.$t("wel.table.devname"),
							prop: "name",
							search: true,
							searchClearable: false,
							searchPlaceholder: '名称搜索',
							searchSize: "mini",
						},
						{
							width: 500,
							label: this.$t("wel.table.code"),
							prop: "code",
							search: true,
							searchClearable: false,
							searchPlaceholder: '编码搜索',
							searchSize: "mini",
							editDisabled:true,

						},
						{
							label: this.$t("wel.table.create_time"),
							prop: "create_time",
							addDisplay: false,
							editDisplay: false,

						},
						{
							label: this.$t("wel.table.start"),
							prop: "start",
							addDisplay: false,
							editDisplay: false,
						},
						{
							label: this.$t("wel.table.remarks"),
							prop: "remarks"
						}, 
						
					]
				};
			}
		},
		created() {},
		methods: {
			searchChange(params,done){
				if(!params){
					this.$message.err("请输入搜索内容");
				}
				done();
				 this.getList({'id':params['id'],'name':params['name'],'code':params['code'],'pageSize':10,'page':1});
				},
			sizeChange(val) {
				this.page.currentPage = 1
				this.page.pageSize = val
				this.getList()
			},

			currentChange(val) {
				this.page.currentPage = val
				this.getList({
					'page': val,
					'pageSize': this.page.pageSize
				});
			},
			delChange(val,index){
				let that = this;
				this.box=true;
				this.delval=val;
				return;
				
			},
			
			delSubmit(){
				let that=this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Equipment/content_del',
						data: that.delval
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info);
						} else if (response.data.status == 1) {
							that.$message.success(response.data.info);
							that.getList({
								'page': that.page.currentPage,
								'pageSize': that.page.pageSize
							});
						}
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});
					that.box=false;
			},
			addChange(val, done, loading) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Equipment/content_addSubmit',
						data: val
					})
					.then(function(response) {
						done();
						if (response.data.status == 0) {
							that.$message.error(response.data.info);
						} else if (response.data.status == 1) {
							that.$message.success(response.data.info);
							that.getList({
								'page': that.page.currentPage,
								'pageSize': that.page.pageSize
							});
						}
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});
			},
			editChange(val, index, done, loading) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Equipment/content_update_submit',
						data: val
					})
					.then(function(response) {
						done();
						if (response.data.status == 0) {
							that.$message.error(response.data.info);
						} else if (response.data.status == 1) {
							that.$message.success(response.data.info);
							that.getList({
								'page': that.page.currentPage,
								'pageSize': that.page.pageSize
							});
						}
					})
					.catch(function(error) {
						console.log(error);
						that.$message.error('系统错误')
					});

			},

			getList(data) {
				let that = this;
				request({
						headers: {
							'Content-Type': 'application/json;charset=utf-8'
						},
						method: 'post',
						url: baseUrl + 'userapi/Equipment/content',
						data: data
					})
					.then(function(response) {
						if (response.data.status == 0) {
							that.$message.error(response.data.info)
						} else if (response.data.status == 1) {
							that.data = response.data.data.data;
							that.data.forEach(function(item, index) {
							       that.data[index].start=item.start==1?"运行":"未运行";
							})
							that.page.total = response.data.data.total;
							that.page.pageSize = response.data.data.per_page;
						}
					})
					.catch(function(error) {
						that.$message.error('系统错误')
					});

			}
		}
	};
</script>

<style scoped="scoped" lang="scss">
	.wel {
		&__header {
			padding: 25px 40px;
			border-bottom: 1px solid #e8e8e8;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		&__info {
			display: flex;
			align-items: center;

			&-img {
				border-radius: 72px;
				display: block;
				width: 72px;
				height: 72px;

				img {
					width: 100%;
					height: 100%;
					display: block;
				}
			}

			&-content {
				position: relative;
				margin-left: 24px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}

			&-title {
				font-size: 20px;
				line-height: 28px;
				font-weight: 500;
				color: rgba(0, 0, 0, 0.85);
				margin-bottom: 12px;
			}

			&-subtitle {
				position: relative;
				font-size: 14px;
				color: rgba(0, 0, 0, 0.45);
				line-height: 22px;
			}
		}

		&__extra {
			&-item {
				position: relative;
				padding: 0 32px;
				display: inline-block;

				&:last-child {
					&::after {
						display: none;
					}
				}

				&:after {
					background-color: #e8e8e8;
					position: absolute;
					top: 30px;
					right: 0;
					width: 1px;
					height: 40px;
					content: "";
				}
			}

			&-title {
				color: rgba(0, 0, 0, 0.45);
				font-size: 14px;
				line-height: 22px;
				margin-bottom: 4px;
			}

			&-subtitle {
				color: rgba(0, 0, 0, 0.85);
				font-size: 30px;
				line-height: 38px;
				margin: 0;

				span {
					color: rgba(0, 0, 0, 0.45);
					font-size: 20px;
				}
			}
		}
	}
</style>
